package cn.jsoup;

import cn.wanghaomiao.xpath.exception.XpathSyntaxErrorException;
import cn.wanghaomiao.xpath.model.JXDocument;
import cn.wanghaomiao.xpath.model.JXNode;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class jsoupDemo5 {
    public static void main(String[] args) throws IOException, XpathSyntaxErrorException {
        String path = jsoupDemo5.class.getClassLoader().getResource("student.xml").getPath();
        //获取html路径
        Document document = Jsoup.parse(new File(path), "UTF-8");
        //将html文件进行解析
        Elements name = document.select("name");
        //通过元素选择器进行选择标签
        System.out.println(name);
        System.out.println("-----");
        document.select("#itcast");
        //通过id选择器进行选择标签
        System.out.println("-----");
        Elements select = document.select("student[number=\"itcast_0001\"]");
        System.out.println(select);
        //通过属性选择器进行选择
        Elements select1 = document.select("student[number=\"itcast_0001\"]>sex");
        //通过直接子类选择器进行选择元素
        System.out.println(select1);


    }
}
